#ifndef FILESYSTEM_H
#define FILESYSTEM_H

#include <string>
#include "lua.hpp"

#ifdef _MSC_VER
    #include <direct.h>
    #define GetCurrentDir _getcwd
    #define FS_PATH_SEPARATOR '\\'
#else
    #include <unistd.h>
    #define GetCurrentDir getcwd
    #define FS_PATH_SEPARATOR '/'
#endif

const int FS_MAX_PATH_LENGTH = 1024;

class Filesystem
{
public:
	Filesystem();
	Filesystem(std::string localPath);

	std::string getTextResource(std::string resName);
	
	// loads a binary resource with the specified name into the buffer dest
	// returns a pointer to a buffer array (that must be freed by the caller!)
	unsigned char* getBinaryResource(std::string resName, int &bytesRead);

	int loadLuaChunk(lua_State* L, std::string resName, std::string debugName);

	std::string formatFilename(std::string resName, std::string resType);

	std::string toAbsolutePath(std::string path);

	// Returns the local absolute path
    std::string getLocalPath();

    void setLocalPath(std::string path);

	~Filesystem();

	static std::string getWorkingDirectory();
private:
    std::string _localPath;
};

#endif
